import { useState, useEffect, useRef } from 'react'
import { useHistory, useDispatch } from 'dva';
import { Button } from 'antd'
import axios from 'axios'

const Login = () => {
  const history = useHistory();
  const input:any = useRef()
  const dispatch:any = useDispatch()
  const [users, setUsers] = useState<any>({})

  return <div>Login

    <input ref={input}/>


     <Button type="primary"
     onClick={() => {
      axios.get('http://localhost:3000/api/login', {
        params: {
          username: 'devin',
          password: '123'
        }
      }).then(res => {
        console.log('res:', res)

        dispatch({
          type: 'users/changeSubmitId',
          payload: input.current.value
        })

        history.push('/detail')
      })
     }}
     >登陆</Button>
  </div>
}

export default Login
